package com.lanxum.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: li.sun
 * @create: 2020-05-02 11:30
 * @description:
 **/
public class CookieFilter extends ZuulFilter {
    private static Logger logger = LoggerFactory.getLogger(CookieFilter.class);

    @Override
    public String filterType() {
        return "post";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        ctx.getResponse().addHeader("Set-Cookie", "JSESSIONID="+request.getSession().getId()+"; Path="+request.getContextPath()+"; Secure; HttpOnly");
        return null;
    }
}
